<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>欢迎登陆</title>
</head>

<body>
  <input type="text" id="username">
  <button id="btn_login">登录</button>
  <script>
    // 1.获取dom节点
    const iUsername = document.querySelector('#username');
    const btnLogin = document.querySelector('#btn_login');
    // 2.绑定点击事件
    btnLogin.addEventListener('click', function () {
      let username = iUsername.value;
      if (username.length < 4) {
        alert('用户名不得少于4位');
        return
      }
      // 会话存储，将username存起来
      sessionStorage.setItem('username', username);
      location.href = './index.html';
    })
  </script>
</body>

</html>